﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes

Public MustInherit Class Entity
    Public mEntityID As String = ""      ' Index of entity
    Public mTableName As String = ""     ' Table that store the Entity
    Public mPKName As String = ""        ' The Entity Index field name

    Protected mSQL As String

    Public mConn As GDataConnection      'lop nay dung de lay connection va thuc thi viec save data

    Public Sub New(ByVal conn As GDataConnection)
        mConn = conn
    End Sub

    Public Sub New(ByVal sEntityID As String, ByVal conn As GDataConnection)
        mEntityID = sEntityID
        mConn = conn
    End Sub

    Public MustOverride Function IsSaveOK() As Boolean

    Public MustOverride Function IsDeleteOK() As Boolean

    Public MustOverride Function GetObjectList(ByVal strStoreProcName As String, ByVal paraList As SqlParameter()) As DataTable

    Public MustOverride Function GetObjectList(ByVal searchCriteria As String) As DataTable

    Public MustOverride Function AddNew() As Boolean

    Public MustOverride Function Update() As Boolean

    Public Overridable Function Delete() As Boolean
        Dim strSQL As String = "Delete from " & mTableName & " where " & mPKName & " = " & mEntityID
        Return mConn.ExecuteNoneQuery(strSQL)
    End Function

    Public MustOverride Function LoadObjectData() As Boolean

    Public Sub Dispose()
        mConn.Conn.Close()
    End Sub

End Class
